#include "topo.h"
#include <fstream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

bool Topo::load_from_json(const std::string& path) {
    std::ifstream in(path);
    if (!in) return false;
    json conf;
    in >> conf;
    int server_count = conf["servers"]["count"];
    int disks_per_server = conf["servers"]["disks_per_server"];
    uint64_t disk_size = conf["servers"]["disk_size_mb"];
    servers_.clear();
    for (int i = 0; i < server_count; ++i) {
        ServerInfo s;
        s.sn = "SERVER_" + std::to_string(i);
        for (int j = 0; j < disks_per_server; ++j) {
            DiskInfo d;
            d.size_gb = disk_size;
            d.sn = "DISK_" + std::to_string(i) + "_" + std::to_string(j);
            s.disks.push_back(d);
        }
        servers_.push_back(s);
    }
    return true;
}

int Topo::total_disk_count() const {
    int cnt = 0;
    for (const auto& s : servers_) cnt += s.disks.size();
    return cnt;
} 